home *** CD-ROM | disk | FTP | other *** search
- /*
- * Vector.h - class definitions for class Vector.
- *
- * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
- * University of Berne, Switzerland
- * All rights reserved.
- *
- * This software may be freely copied, modified, and redistributed
- * provided that this copyright notice is preserved on all copies.
- *
- * You may not distribute this software, in whole or in part, as part of
- * any commercial product without the express consent of the authors.
- *
- * There is no warranty or other guarantee of fitness of this software
- * for any purpose. It is provided solely "as is".
- *
- */
-
- #ifndef Vector_H
- # define Vector_H
-
- #include <iostream.h>
- #include <math.h>
-
- #include "mathutilities.h"
- #include "Error.h"
-
- //___________________________________________________________ Vector
-
- class Vector
- {
- public:
- Vector();
- Vector(const real, const real, const real);
- Vector(const Vector&);
-
- real& operator[](int i);
- real operator[](int i) const;
-
- const Vector& operator=(const Vector&);
- Vector& operator+=(const Vector&);
- Vector& operator-=(const Vector&);
- Vector& operator*=(const Vector&);
- Vector& operator*=(const real);
- Vector& operator/=(const real);
-
- int operator==(const Vector&) const;
- int operator!=(const Vector&) const;
-
- real sqr() const; // squared length of vector
- real length() const; // length of vector
- int zero() const;
- real distance(const Vector&) const; // distance between two points
- real normalize(); // normalize vector
- Vector normalized() const; // generate normalized vector
-
- Vector operator-() const; // negation
- Vector operator+(const Vector&) const; // vector addition
- Vector operator-(const Vector&) const; // vector subtraction
- Vector operator*(const Vector&) const; // vector cross product
- real operator^(const Vector&) const; // vector dot product
- Vector operator/(const real) const; // scalar divison
-
- // scalar multiply
- friend Vector operator*(real, const Vector&);
- friend Vector operator*(const Vector&, real);
-
- friend ostream& operator<<(ostream&, const Vector&);
-
- static void swap(Vector&, Vector&);
-
- private:
- real v[3];
- };
-
- inline real& Vector::operator[](int i)
- {
- #ifndef __OPTIMIZE__
- if (i<0 || i>2)
- Error(ERR_PANIC, "Vector::operator[] index out of range");
- #endif
-
- return v[i];
- }
-
- inline real Vector::operator[](int i) const
- {
- #ifndef __OPTIMIZE__
- if (i<0 || i>2)
- Error(ERR_PANIC, "Vector::operator[] index out of range");
- #endif
-
- return v[i];
- }
-
- #endif // Vector_H
-
-